import { computed, ref } from 'vue'
import { defineStore } from 'pinia'

export const useDeviceStore = defineStore('device', () => {
  const device = ref(new Map())
  const deviceIds = ref<any[]>([])
  const deviceById = computed(() => {
    return (id: any) => device.value.get(id)
  })
  function setDevice( data: any) {

    data.forEach((item: any) => {
      device.value.set(item.deviceId,item)
      deviceIds.value.push(item.deviceId)
    })
    
  }
  return {
    deviceById,
    setDevice,
    deviceIds
  }
})